package destiny.music;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;

import javax.xml.parsers.SAXParserFactory;

import destiny.music.entity.Music;
import destiny.music.view.model.MusicListAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.database.DataSetObserver;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class ListActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list);

		try {
			Vector<Music> musics = MyToolkit.parse(new URL(
					"http://192.168.1.100:8080/AndoridServer/music/list")
					.openStream());
			ListView listView = (ListView) findViewById(R.id.listView1);
			listView.setAdapter(new MusicListAdapter(musics, this));
			Button button = (Button) findViewById(R.id.exidBtn);
			button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					System.exit(0);
				}
			});
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_start, menu);
		return true;
	}

}
